package cn.est.controller;
import cn.est.pojo.MaintainOrderFlow;
import cn.est.constants.Constants;
import cn.est.dto.Page;
import cn.est.dto.Result;
import cn.est.service.MaintainOrderFlowService;
import cn.est.utils.EmptyUtils;
import cn.est.utils.ResultUtils;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Map;

@Controller
@RequestMapping("/client/maintainOrderFlow")
public class MaintainOrderFlowController {

    @Resource
    private MaintainOrderFlowService maintainOrderFlowService;

    @RequestMapping("/search")
    @ResponseBody
    public Page<MaintainOrderFlow> searchMaintainOrderFlow(@RequestParam Map<String,Object> param) {
        Page<MaintainOrderFlow> maintainOrderFlowPage = null;
        try {
            Integer pageNo= EmptyUtils.isEmpty(param.get("pageNo"))? Page.DEFAULT_PAGE_NO:Integer.parseInt((String) param.get("pageNo"));
            Integer pageSize= EmptyUtils.isEmpty(param.get("pageSize"))? Page.DEFAULT_PAGE_SIZE:Integer.parseInt((String) param.get("pageSize"));
            maintainOrderFlowPage  = maintainOrderFlowService.queryMaintainOrderFlowPageByMap(param, pageNo, pageSize);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return maintainOrderFlowPage;
    }

    @RequestMapping("/saveOrUpdateMaintainOrderFlow")
    @ResponseBody
    public Result saveOrUpdateMaintainOrderFlow(MaintainOrderFlow maintainOrderFlow){
        Integer flag=0;
        try {
            if(EmptyUtils.isEmpty(maintainOrderFlow.getId())){
                flag=maintainOrderFlowService.qdtxAddMaintainOrderFlow(maintainOrderFlow);
            }else{
                flag=maintainOrderFlowService.qdtxModifyMaintainOrderFlow(maintainOrderFlow);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag>=1?ResultUtils.returnSuccess():ResultUtils.returnFail();
    }

    @RequestMapping("/getMaintainOrderFlowById")
    @ResponseBody
    public Result getMaintainOrderFlowById(Long id){
        Result result= ResultUtils.returnSuccess();
        MaintainOrderFlow maintainOrderFlow=null;
        try {
            maintainOrderFlow=maintainOrderFlowService.getMaintainOrderFlowById(id);
            result.setData(maintainOrderFlow);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping("/batchRemoveMaintainOrderFlow")
    @ResponseBody
    public Result batchRemoveMaintainOrderFlow(String ids){
        Integer flag=0;
        try {
            flag=maintainOrderFlowService.qdtxBatchDeleteMaintainOrderFlow(ids);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtils.returnSuccess();
    }

    @RequestMapping("/removeMaintainOrderFlowById")
    @ResponseBody
    public Result removeMaintainOrderFlowById(Long id){
        Integer flag=0;
        try {
            flag=maintainOrderFlowService.qdtxDeleteMaintainOrderFlowById(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtils.returnSuccess();
    }
}
